'''
行业分析
'''
import datetime

from flask import jsonify, request

from db.dao import StockFundsDao, MarketWorkDayDao
from utils.util import FlaskTool
from web import custom


@custom.route('/stock/fund/ranking')
def stockFundsRank():
    '''
    股票行业单日涨幅查询
    :return:
    '''
    weeks = request.args.get('weeks', type=int)
    tops = request.args.get('tops', type=int)
    industry_name = request.args.get('industry_name')
    trading_day_list = MarketWorkDayDao().queryLastWorkDay(datetime.date.today(), limit=weeks * 5)
    listResult = []
    if trading_day_list:
        for startDate in trading_day_list:
            list = StockFundsDao().findBySql(industry_name=industry_name, create_date=startDate, limit=tops)
            if list:
                for industrySectorFunds in list:
                    setattr(industrySectorFunds, 'groupname', startDate)
                    listResult.append(industrySectorFunds)

    return jsonify(FlaskTool.modelList(listResult))




